package com.zzptc.easyshop.control;

import com.zzptc.easyshop.dao.GoodTypeDaoImp;
import com.zzptc.easyshop.facory.DaoFacoryImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "NewGoodTypeServlet")
public class NewGoodTypeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //处理乱码  写在流之前
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw=response.getWriter();
        pw.print("啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦");

        //request.getParameter("");
        GoodTypeDaoImp goodTypeDaoImp=null;
        try {
         goodTypeDaoImp= (GoodTypeDaoImp) DaoFacoryImp.getInstance().createDAO("GoodTypeDaoImp");
        } catch (Exception e) {
            e.printStackTrace();
        }
        //调用dao方法
        List list =goodTypeDaoImp.getAll();
        //响应过程
        request.setAttribute("all",list);
        request.getRequestDispatcher("/showtype.jsp").forward(request,response);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doPost(request,response);
    }
}
